home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CUJ9206.ARJ / 1006091A < prev    next >
Text File  |  1992-06-02  |  791b  |  43 lines

  1. /* LISTING 6 */
  2.  
  3. #define DM2init                 struct DM2 \
  4.         { int rows, cols; double * data; }
  5.  
  6. #define DM2type                 struct DM2
  7.  
  8. DM2init;
  9.  
  10. DM2type DM2alloc(DM2type *p, int r, int c) {
  11.     p->rows = r;
  12.     p->cols = c;
  13.     p->data = (double *)
  14.         malloc((unsigned)r*c*sizeof(double));  
  15.  
  16.     return *p;
  17. }
  18.  
  19. #define DM2item(x,i,j)          x.data[i*x.cols+j]
  20.  
  21. void DM2free(DM2type * x) {
  22.     free((void *)x->data);
  23. }
  24.  
  25. main()
  26. {
  27.     DM2type m;
  28.     int i,j;
  29.  
  30.     DM2alloc(&m, 7,13);
  31.     for(i=0; i<7; ++i)
  32.         for(j=0; j<13; ++j)
  33.             DM2item(m,i,j) = (double) (i*100)+j;
  34.  
  35.     for(i=0; i<7; ++i) {
  36.         for(j=0; j<13; ++j)
  37.             printf("%3g ",DM2item(m,i,j) );
  38.         printf("\n");
  39.     }
  40.     DM2free(&m);
  41. }
  42.  
  43.